<template>
    <div>
        <div class="block">
            <div v-if="!tableData.length" style="text-align: center;margin: 1rem 0;">暂无信息</div>
            <template v-if="tableData.length">
                <div class="item" v-for="(v,index) in tableData" @click="goDetail(v)">
                    <div><span class="tit">时间</span>：{{v.create_time}}</div>
                    <div><span class="tit">主题</span>：{{v.title}}</div>
                    <div><span class="tit">详细信息</span>：<div class="text">{{v.content}}</div></div>
                    <!--<span class="el-icon-lx-delete" @click="delAddress"></span>-->
                </div>
            </template>
        </div>
    </div>
</template>

<script>
    export default {
        name: "notice",
        data(){
            return{
                tableData: [],
                pageSize: 0,
                totalRow: 0,
                currentPage1: 0,

                loginInfo: {},
            }
        },
        methods: {
            loadopen() {
                this.loading = this.$loading({lock: true,text: 'Loading',spinner: 'el-icon-loading',background: 'rgba(0, 0, 0, 0.2)'});setTimeout(() => {this.loading.close();}, 5000);
            },
            loadclose() {this.loading.close();},
            // 分页导航
            handleCurrentChange(val) {
            },
            // 获取登录用户信息
            getLoginInfo() {
                this.loadopen();
                this.config.mpost('/api/housinggestate/findMyHousinggestate', {}).then(res=>{
                    this.loadclose();
                    if(res.data.code==='0'){
                        if(res.data.userAddressList.length<=1){
                            this.loginInfo = res.data.userAddressList[0];
                        }else{
                            res.data.userAddressList.forEach(it=>{
                                if(it.is_default==='1'){
                                    this.loginInfo = it;
                                }
                            })
                        }
                        this.getData('1')
                    }else {
                        this.$message.error(this.config.mobileError(res.data));
                    }
                })
            },
            // 获取列表数据
            getData(pageNumber) {
                this.loadopen();
                this.config.mpost('/api/convenience/convenience/findPage', {
                    pageNum: pageNumber?pageNumber:1,
                    housinggestateId: this.loginInfo.housinggestate_id,
                }).then(res=>{
                    this.loadclose();
                    if(res.data.code==='0'){
                        this.tableData = res.data.page.list;
                        this.pageSize = res.data.page.pageSize;
                        this.totalRow = res.data.page.totalRow;
                        this.currentPage1 = res.data.page.pageNumber;
                    }else {
                        this.$message.error(this.config.mobileError(res.data));
                    }
                })
            },
            goDetail(v){
                console.log(v.id)
                this.$router.push({path: '/mobile/notice-detail', query: {id: v.id, housinggestateId: this.loginInfo.housinggestate_id}})
            },
            search() {
            },
            // 分页导航
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
                this.getData(val);
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
        },
        mounted(){
            this.getLoginInfo()
        }
    }
</script>

<style scoped lang="less">
    .block{
        .item{
            color: #333;
            padding: .5rem 1rem;
            margin: .8rem;
            box-shadow: 0 0 10px 0 #ccc;
            border-radius: 6px;
            position: relative;
            .tit{
                color: #666;
            }
            .el-icon-lx-delete{
                position: absolute;top: 10px;right: 10px;color: #8c939d;
            }
        }
    }

    .text{
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
    }
</style>
